﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using NexTrackDesktop.NexTrack;

namespace NexTrackDesktop.Media
{
    /// <summary>
    /// This class stores all queue related info and events.
    /// No consideration for size of queue.
    /// </summary>
    public class Queue
    {
        private List<QueueItem> _queue;

        public ReadOnlyCollection<QueueItem> Items
        {
            get
            {
                return new ReadOnlyCollection<QueueItem>(_queue);
            }
        }

        /// <summary>
        /// This method creates a new empty Queue.
        /// </summary>
        public Queue()
        {
            _queue = new List<QueueItem>();
        }

        /// <summary>
        /// This method contacts the web service via Client and updates queue
        /// </summary>
        public void UpdateQueue()
        {
            _queue = Client.Instance.WebService.GetQueue();

            if (QueueUpdated != null)
                QueueUpdated();
        }
        
        public event Action QueueUpdated;

        ///// <summary>
        ///// This method adds the specified song to the queue if not in queue already.
        ///// </summary>
        ///// <param name="song">Song to add to queue</param>
        //public void AddItem(Song song)
        //{
        //    bool alreadyExists = false;
        //    // check if song is already in queue
        //    foreach (QueueItem item in _queue)
        //    {
        //        if (item.Song.Equals(song))
        //        {
        //            alreadyExists = true;
        //        }
        //    }
        //    if (!alreadyExists)
        //    {
        //        _queue.Add(new QueueItem(song));
        //    }
            
        ///// <summary>
        ///// This method removes the specified song from the queue if in queue.
        ///// </summary>
        ///// <param name="song">Song to remove from queue</param>
        //public void RemoveItem(Song song)
        //{
        //    // search queue for song, remove if found
        //    foreach (QueueItem item in _queue)
        //    {
        //        if (item.Song.Equals(song))
        //        {
        //            _queue.Remove(item);
        //        }
        //    }
        //}

        //// Events triggered when queue is changed.
        //public event Action<Song> ItemAdded;
        //public event Action<Song> ItemRemoved;
    }
}
